﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.IO;
using System.Web.Hosting;
using System.ServiceModel;
using ListenMusic.Models.ViewModel;
namespace ListenMusic.Models.Reposistory.Public
{
    public class DowloadReposistory
    {
        public List<FilesName> GetFiles()
        {
            List<FilesName> lstFiles = new List<FilesName>();
            DirectoryInfo dirInfo = new DirectoryInfo(HostingEnvironment.MapPath("~/Music"));
            int i = 0;
            foreach (var item in dirInfo.GetFiles())
            {
                lstFiles.Add(new FilesName()
                {
                    FileId = i + 1,
                    FileName = item.Name,
                    FilePath = dirInfo.FullName + @"\" + item.Name,

                }
                            );
                i = i + 1;
            }
            return lstFiles;
        }
        public string getFileDowload(string url, List<FilesName> files)
        {
            try
            {
                string filename = (from f in files
                                   where f.FileName == url
                                   select f.FilePath).First();
                return filename;
            }
            catch (Exception ex)
            {
                throw new FaultException(ex.Message);
            }
        }
     
    }
}